home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Extras / Development / Example_Code_v37 / Libraries / Intuition / boopsi / demopubi.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-27  |  3.5 KB  |  153 lines

  1. /* demopubi.c -- demonstration of         :ts=8
  2.  * public image class.
  3.  */
  4.  
  5. /*
  6. Copyright (c) 1989, 1990-1999 Amiga, Inc.
  7.  
  8. Executables based on this information may be used in software
  9. for Amiga computers. All other rights reserved.
  10. This information is provided "as is"; no warranties are made.
  11. All use is at your own risk, and no liability or responsibility
  12. is assumed.
  13. */
  14.  
  15. #include "sysall.h"
  16.  
  17. #define D(x)    ;
  18.  
  19. struct  IntuitionBase   *IntuitionBase;
  20. struct  GfxBase         *GfxBase;
  21. struct  Library         *UtilityBase;
  22.  
  23. /* class pointer is an abstract handle, which
  24.  * one never uses for "public" access to a class,
  25.  * but we as class owner can use for private access,
  26.  * or to free the class.
  27.  */
  28. void    *initEmbBClass();
  29. void    *EmbBClass;
  30.  
  31. ULONG    myiflags = CLOSEWINDOW;
  32.  
  33. struct Image    *myimage;
  34.  
  35. main()
  36. {
  37.     struct DrawInfo    *GetScreenDrawInfo();
  38.     struct Window     *OpenWindowTags();    /* in varargs.c for now */
  39.     struct Window    *w;
  40.     struct DrawInfo    *drinfo;
  41.  
  42.     openAll();    /* get libraries open    */
  43.  
  44.     D( printf("about to openwindow\n") );
  45.     w = OpenWindowTags( NULL,
  46.         WA_Title,    "Public Image Test Window",
  47.         WA_SimpleRefresh, TRUE,
  48.         WA_NoCareRefresh, TRUE,
  49.         WA_DepthGadget,    TRUE,
  50.         WA_DragBar,    TRUE,
  51.         WA_Left,    300,
  52.         WA_Top,        50,
  53.         WA_Width,    280,
  54.         WA_Height,    120,
  55.         WA_IDCMP,    myiflags,
  56.         WA_CloseGadget,    TRUE,
  57.             TAG_END );
  58.     D( printf("window at %lx\n ", w ) );
  59.     if ( w == NULL) cleanup( "couldn't open my window.\n");
  60.  
  61.     drinfo = GetScreenDrawInfo( w->WScreen );
  62.  
  63.     /* init the public class    */
  64.     EmbBClass = initEmbBClass();
  65.  
  66.     /* create an image from my public class    */
  67.     myimage =  (struct Image *) NewObject(  NULL,  "emboxclass",
  68.             IA_WIDTH, 20,
  69.             IA_HEIGHT, 10,
  70.                 TAG_END );
  71.  
  72. #define XPOS    (40)
  73. #define YPOS    (20)
  74. #define XPOS2    (XPOS + 30)
  75.  
  76.     /* draw the image    */
  77.     DrawImageState( w->RPort, myimage, XPOS, YPOS, IDS_NORMAL, drinfo );
  78.  
  79.     /* draw the image    */
  80.     DrawImageState( w->RPort, myimage, XPOS2, YPOS, IDS_SELECTED, drinfo );
  81.  
  82.     /* go away and be done    */
  83.     goHandleWindow( w );
  84.  
  85.     FreeScreenDrawInfo( w->WScreen, drinfo );
  86.     CloseWindow( w );
  87.  
  88.     DisposeObject( myimage );
  89.     D( printf("have disposed.\n") );
  90.  
  91.     /* get rid of the public class.
  92.      * Don't really exit unless the class can be free'd,
  93.      * since that would mean that somebody might want to use
  94.      * your class's implementation routines after you're gone.
  95.      */
  96.     if ( ! freeEmbBClass( EmbBClass ) )
  97.     {
  98.     cleanup( "PANIC: exiting with class not free'd!\n" );
  99.     }
  100.  
  101.     cleanup( "all done" );
  102. }
  103.  
  104. cleanup( str )
  105. char    *str;
  106. {
  107.     if (str) printf("%s\n", str);
  108.  
  109.     if (IntuitionBase) CloseLibrary(IntuitionBase);
  110.     if (GfxBase) CloseLibrary(GfxBase);
  111.     if (UtilityBase) CloseLibrary(UtilityBase);
  112.  
  113.     exit (0);
  114. }
  115.  
  116. /* exits via cleanup() if failure    */
  117. openAll()
  118. {
  119.     if (!(UtilityBase=(struct Library *)OpenLibrary("utility.library",36L)))
  120.     { cleanup("no V36 utility library\n"); }
  121.  
  122.     if (!(IntuitionBase =
  123.     (struct IntuitionBase *) OpenLibrary("intuition.library", 36L)))
  124.     { cleanup("no V36 intuition library\n"); }
  125.  
  126.     if (!(GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 36L)))
  127.     { cleanup("no V36 graphics library\n"); }
  128. }
  129.  
  130. goHandleWindow( w )
  131. struct Window    *w;
  132. {
  133.     struct IntuiMessage *imsg;
  134.     for(;;)
  135.     {
  136.     WaitPort( w->UserPort );
  137.     while ( imsg = (struct IntuiMessage *) GetMsg( w->UserPort ) )
  138.     {
  139.         switch ( imsg->Class )
  140.         {
  141.         case CLOSEWINDOW:
  142.             ReplyMsg( (struct Message *) imsg );
  143.         return;
  144.  
  145.         default:
  146.         D( printf("unknown message \n", imsg->Class));
  147.         break;
  148.         }
  149.         ReplyMsg( (struct Message *) imsg );
  150.     }
  151.     }
  152. }
  153.